import e from "jquery";
import t from "./view";
import n from "./color";
import r from "./text_align";
import i from "./text_v_align";

export default class Text extends t {
  className = "AXEText";
  clone() {
    let e = this,
      t = new Text();
    return e.copyProperties(t), t;
  }
  copyProperties(e) {
    let n = this;
    t.prototype.copyProperties.call(n, e),
      n.color() != null && e.color(n.color()),
      n.font() != null && e.font(n.font()),
      e.lineHeight(n.lineHeight()),
      e.wordWrap(n.wordWrap()),
      e.size(n.size()),
      e.style(n.style()),
      e.textAlign(n.textAlign()),
      e.textVAlign(n.textVAlign()),
      e.text(n.text()),
      e.mergeLastLine(n.mergeLastLine());
  }
  updatePropsFromXML(r) {
    let i = this;
    t.prototype.updatePropsFromXML.call(i, r),
      r.is("[merge-last-line]") &&
        i.mergeLastLine(parseInt(r.attr("merge-last-line"), 10)),
      r.is("[color]") && i.color(n.colorWithString(r.attr("color"))),
      r.is("[font]") && i.font(r.attr("font")),
      r.is("[size]") && i.size(parseFloat(r.attr("size"))),
      r.is("[style]") && i.style(r.attr("style")),
      r.is("[text-align]") && i.textAlign(r.attr("text-align")),
      r.is("[text-v-align]") && i.textVAlign(r.attr("text-v-align")),
      r.is("[word-wrap]") && i.wordWrap(r.attr("word-wrap") == "true"),
      r.is("[line-height]") && i.lineHeight(parseFloat(r.attr("line-height"))),
      i.text(e.trim(r.text()));
  }
  _mergeLastLine = 0;
  mergeLastLine(e?) {
    let t = this;
    return (
      isNaN(e) == 0 &&
        t._mergeLastLine != Math.abs(e) &&
        ((t._mergeLastLine = Math.abs(e)), t.needToRender(!0)),
      t._mergeLastLine
    );
  }
  _lineHeight = 0;
  lineHeight(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        e != t._lineHeight &&
        ((t._lineHeight = e), t.needToRender(!0)),
      t._lineHeight
    );
  }
  _wordWrap = !1;
  wordWrap(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        e != t._wordWrap &&
        ((t._wordWrap = e), t.needToRender(!0)),
      t._wordWrap
    );
  }
  _color = null;
  color(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        e != t._color &&
        ((t._color = e), t.needToRender(!0)),
      t._color
    );
  }
  _font = "sans-serif";
  font(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        typeof e == "string" &&
        t._font != e &&
        ((t._font = e), t.needToRender(!0)),
      null
    );
  }
  _size = 12;
  size(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        isNaN(parseFloat(e)) === !1 &&
        parseFloat(e) != t._size &&
        ((t._size = parseFloat(e)), t.needToRender(!0)),
      t._size
    );
  }
  _style = null;
  style(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        typeof e == "string" &&
        e != t._style &&
        ((t._style = e), t.needToRender(!0)),
      t._style
    );
  }
  textStyle() {
    let e = this,
      t = [];
    return (
      e._style != null && t.push(e._style),
      e._size != null && t.push(e._size + "px"),
      e._font != null && t.push(e._font),
      t.join(" ")
    );
  }
  _textVAlign = i.ALPHABETIC;
  textVAlign(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        typeof e == "string" &&
        t._textVAlign != e &&
        ((t._textVAlign = e), t.needToRender(!0)),
      t._textVAlign
    );
  }
  _textAlign = r.LEFT;
  textAlign(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        typeof e == "string" &&
        e != t._textAlign &&
        ((t._textAlign = e), t.needToRender(!0)),
      t._textAlign
    );
  }
  _text = "";
  text(e?) {
    let t = this;
    return (
      arguments.length > 0 &&
        t._text != e &&
        ((t._text = String(e)), t.needToRender(!0)),
      t._text
    );
  }
}
